import req from '@/utils/request'
const pre = '/loan'
export const createLoanApi = (loan) => req.post(pre + '/create', loan)
export const getLoanList = (pager) =>
  req.get(pre + '/list', {
    params: pager,
  })
export const updateLoanInfo = (loan) =>
  req.put(pre + '/update', loan, {
    fullLoading: true,
  })
export const deleteLoanById = (id) =>
  req.delete(pre + '/delete/' + id, {
    fullLoading: true,
  })

export const submitLoanById = (id) =>
  req.post(
    pre + '/submitToApprove',
    { id },
    {
      fullLoading: true,
    }
  )
export const passLoan = (appId, loanId) =>
  req.post('/approve/first/pass', {
    appId,
    loanId,
  })
export const rejectLoan = (appId) =>
  req.post('/approve/first/reject', {
    appId,
  })
export const getEndLoanInfo = (id) => req.get(pre + '/query?id=' + id)
export const passEndLoan = (appId) =>
  req.post('/approve/end/pass', {
    appId,
  })
export const rejectEndLoan = (appId) =>
  req.post('/approve/end/reject', {
    appId,
  })
export const makeContract = (id) =>
  req.post(
    '/contract/createFile',
    { id },
    {
      fullLoading: true,
    }
  )
export const downloadContractUrl = (id) =>
  req.get(`/contract/download?id=${id}`, {
    fullLoading: true,
  })

export const downloadContract = (url) =>
  req(
    {
      url,
      responseType: 'blob', // arrayBuffer blob 浏览器常见的文件
    },
    { fullLoading: true }
  )
